package sam.msm.commons.util;
import java.io.IOException;

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

@SuppressWarnings("restriction")
public class Base64
{
  public static String encode(byte[] data)
  {
    BASE64Encoder base64Encoder = new BASE64Encoder();
    return filter(base64Encoder.encode(data));
  }
  
  public static byte[] decodeBuffer(String data)
    throws IOException
  {
    BASE64Decoder base64Decoder = new BASE64Decoder();
    return base64Decoder.decodeBuffer(data);
  }
  
  private static String filter(String str)
  {
    String output = null;
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < str.length(); i++)
    {
      int asc = str.charAt(i);
      if ((asc != 10) && (asc != 13)) {
        sb.append(str.subSequence(i, i + 1));
      }
    }
    output = new String(sb);
    return output;
  }
}
